//
//  LDXOAuthViewController.swift
//  微博
//
//  Created by 吕东星 on 17/4/2.
//  Copyright © 2017年 lddongxing. All rights reserved.
//

import UIKit
//  微博的AppKey
let AppKey = "3278515534"
//  授权回调页地址
let Redirect_Uri = "http://www.itcast.cn"


class LDXOAuthViewController: UIViewController {
    //懒加载webView控件
   private lazy var webView: UIWebView = UIWebView()
    // 加载视图
    override func loadView() {
        view = webView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //       view.backgroundColor = UIColor.red
        setupNav()
        requestOAuth()
    }
    
    // 请求地址
    func requestOAuth()  {
        let strUrl = "https://api.weibo.com/oauth2/authorize?client_id=\(AppKey)&redirect_uri=\(Redirect_Uri)"
        let urlRequest = URLRequest(url: URL(string: strUrl)!)
        webView.loadRequest(urlRequest)
    }
    
    
    
    
    //设置导航栏和标题
    private func setupNav(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "取消", target: self, action: #selector(cancelAction))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "自动登录", target: self, action: #selector(loginFillAction))
    }
    
    
    func cancelAction()  {
        dismiss(animated: true, completion: nil)
    }
    func loginFillAction()  {
        print("自动登录")
    }
    
    

}
